import React, { useState } from "react";

interface AddItemProps {
  onAdd: (text: string) => void;
}
const AddItem = ({ onAdd }: AddItemProps) => {
  const [value, setValue] = useState("");

  const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
    console.log("value", value);
    e.preventDefault();
    if (!value) return;
    onAdd(value);
    setValue("");
  };

  const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
    setValue(e.target.value);
  };

  return (
    <div>
      <form onSubmit={handleSubmit}>
        <input
          type="text"
          placeholder="请输入任务"
          value={value}
          onChange={e=>handleChange(e)}
        />
        <button type="submit">添加</button>
      </form>
    </div>
  );
};

export default AddItem;
